/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farmcode.console.ejb.business.custom;

import com.farmcode.base.dao.BaseFilter;
import com.farmcode.base.dao.DAOException;
import com.farmcode.base.manager.FacadeException;
import com.farmcode.console.api.business.BaseTemplateManagerBean;
import com.farmcode.console.api.business.custom.ExtTemplateManager;
import com.farmcode.console.api.model.PackageTemplate;
import com.farmcode.console.api.model.Template;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Local;
import javax.ejb.Stateless;

/**
 *
 * @author Oscar Ivan Prado
 */
@Local(ExtTemplateManager.class)
@Stateless
public class ExtTemplateManagerBean extends BaseTemplateManagerBean implements ExtTemplateManager{

    @Override
    public List<Template> getTemplatesByPackage(PackageTemplate packageTemplate) throws FacadeException{
        setBaseFilter(new TemplateFilter(packageTemplate));
        try {
            return templateDAO.find();
        } catch (DAOException ex) {
            Logger.getLogger(ExtTemplateManagerBean.class.getName()).log(Level.SEVERE, null, ex);
            throw new FacadeException(ex);
        }
    }

    class  TemplateFilter extends BaseFilter{
        private PackageTemplate  packageTemplate;

        public TemplateFilter(PackageTemplate packageTemplate) {
            this.packageTemplate = packageTemplate;
        }
        
        @Override
        public void fill() {
            setParameter("template", "template.packageTemplate = ", packageTemplate);
        }
        
    }
    
}
